package com.example.HaiDLaobackend.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.HaiDLaobackend.common.ApiResponse;
import com.example.HaiDLaobackend.entity.CategoryEntity;
import com.example.HaiDLaobackend.service.CategoryService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/categories")
public class CategoryController {

	private final CategoryService categoryService;

	public CategoryController(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	@GetMapping
	public ApiResponse<List<CategoryEntity>> list() {
		List<CategoryEntity> list = categoryService.list(new LambdaQueryWrapper<CategoryEntity>()
			.orderByAsc(CategoryEntity::getSortOrder));
		return ApiResponse.ok(list);
	}
}


